<?php
namespace Content\Controller;
use Common\Controller\AdminbaseController;
class ImageController extends AdminbaseController 
{   
	  protected $imageObj;
    public function _initialize()
    {      
      parent::_initialize();
      $this->imageObj = D("Image");
    }

	public function index()
	{
			$this->lists();
	}

	public function lists()
	{
        $condition = array();
        $count      =  $this->imageObj->where($condition)->count();
        $Page       = new \Think\Page($count,15);
        $show       = $Page->show();
        $list = $this->imageObj->where($condition)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign('page',$show); 
        $this->display('list');
	}

    

    public function save($src,$alt)
    {
        $id = I('post.inputId','','htmlspecialchars');
        $name = I('post.inputName','','htmlspecialchars');
        $data = array();
        $data["name"]  = $name;
        if($id>0)
        {
            $editResult = $this->imageObj->where("id=%d",$id)->save($data);
            $arr = array("status"=>'1',"message"=>"编辑文章分类成功","url"=>"index");
        }
        else
        {
            $addResult =  $this->imageObj->add($data);
            if($addResult) {
                $arr = array("status"=>'1',"message"=>"添加文章分类成功","url"=>"index");
            }else{
                $arr = array("status"=>'0',"message"=>"添加文章分类失败");
            }
        }
        echo json_encode($arr);
    }


	/*排序更新*/
    public function listorder()
    {
       $ids = I('post.ids','-1','htmlspecialchars');
       $listorders = I('post.listorders','','htmlspecialchars');  
       parent::_listorder($this->imageObj,$ids,$listorders);
    }
    /*单个删除 id*/
    public function delete($id)
    {
        parent::_delete($this->imageObj,$id);
    }

    /* 批量删除 ids*/
    public function checkDeletes($ids)
    {
      parent::_checkDeletes($this->imageObj,$ids);
    }
    /* 单个修改当前状态status 0 1 -1*/
    public function changeStatus($id,$status)
    {
        parent::_changeStatus($this->imageObj,$id,$status);
    }
    /*批量 修改当前状态status 0 1 -1*/
    public function checkChanges($status,$ids)
    {
      parent::_checkChanges($this->imageObj,$status,$ids);
    }
}
?>